<?php

namespace App\Http\Resources\Customer;

use App\model\customer\Customer;
use App\User;
use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Support\Carbon;

class CustomerCollection extends ResourceCollection
{
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {


        return [
            'code'=>200,
            'data'=>$this->collection->map(function (Customer $item){
               $status='';
              return [
                  'code'=>$item->code,
                  'address'=>$item->address,
                  'name'=>$item->name,
                  'hangye'=>$item->hangye_format,
                  'area'=>$item->area_format,
                  'soure'=>$item->source_format,
                  'customer_id'=>$item->customer_id,
                  'created_at'=>Carbon::parse($item->created_at)->format('Y/m/d H:i'),
                 // 'status'=>Customer::$statusMap[$item->status]
                  'desc'=>$item->desc,
                  'status'=>$item->status,
                  'depart'=>$item->depart ?? ['id'=>0,'name'=>''],
                  'follow_status'=>$item->follow_status,

                  'can_fenpei'=>$item->is_chongfen
                ];
            })
        ];
    }
}
